package com.zrf.service;

import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zrf.dao.impl.BuyerDaoImpl;
import com.zrf.dao.impl.ProductDaoImpl;
import com.zrf.dao.impl.ShoppingcartDaoImpl;
import com.zrf.hibernate.model.MyShoppingCart;
import com.zrf.hibernate.pojo.Product;
import com.zrf.hibernate.pojo.Shoppingcart;


@Service("shoppingcartService")
public class ShoppingCartService {

	@Autowired
	private BuyerDaoImpl bdi = null;
	@Autowired
	private ProductDaoImpl pdi = null;
	@Autowired
	private ShoppingcartDaoImpl scdi = null;
	
	
	public List<MyShoppingCart> byName(String name){
		return scdi.findByName(name);
	}
	
	
	public boolean deleteShoppingcart(Integer scid){
		try {
			Shoppingcart sc = scdi.findById(scid);
			Product p = pdi.findById(sc.getProduct().getProductid());
			p.setPnum(p.getPnum()+sc.getNum());
			pdi.update(p);
			scdi.deleteById(scid);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return false;
	}
	
	
}
